/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SysAguas.visao;

import SysAguas.controle.Erro;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.JFrame;

/**
 *
 * @author Heitor
 */
public class PanelConsultarReserva extends JPanel implements ActionListener {

    private JPanel jpanelUm, jpanelUm2, jpanelUm3, jpanelUm4, jpanelDois,
            jpanelDois2, jpanelTres, jpanelTres2, jpanelCinco, jpanelTres3, jpanelQuatro;
    private JButton buttonBuscar, buttonAtualizar,
            buttonRemover, buttonListar, buttonFechar;
    private JLabel tituloL, hospedeL, idReservaL, hospede2L,
            dataCHL, dataSAL, descontoL, statusL;
    private JTextField hospedeT, idReservaT, hospede2T,
            dataCHT, dataSAT, descontoT, statusT;
    private JTable tabela, tabelaQuarto;
    private DialogAtualizarReserva atualizarReservaDialog;

    public PanelConsultarReserva() {
        super();

        jpanelUm = new JPanel();
        jpanelUm2 = new JPanel();
        jpanelUm3 = new JPanel();
        jpanelUm4 = new JPanel();

        jpanelDois = new JPanel();
        jpanelDois2 = new JPanel();

        jpanelTres = new JPanel();
        jpanelTres2 = new JPanel();
        jpanelTres3 = new JPanel();

        jpanelQuatro = new JPanel();
        jpanelCinco = new JPanel();

        buttonBuscar = new JButton("Buscar");
        buttonBuscar.addActionListener(new Erro());

        buttonAtualizar = new JButton("Atualizar");
        buttonAtualizar.addActionListener(this);

        buttonRemover = new JButton("Remover");
        buttonRemover.addActionListener(new Erro());

        buttonListar = new JButton("Listar Todas");
        buttonListar.addActionListener(new Erro());

        buttonFechar = new JButton("Fechar");
        buttonFechar.addActionListener(this);

        tituloL = new JLabel("Consultar Reservas");
        hospedeL = new JLabel("Hóspede:");
        idReservaL = new JLabel("ID da Reserva:");
        hospedeT = new JTextField(10);
        idReservaT = new JTextField(7);

        tabela = new JTable(4, 6);
        tabela.setModel(new javax.swing.table.DefaultTableModel(new Object[][]{
                    null, null, null, null, null, null,
                    null, null, null, null, null, null,
                    null, null, null, null, null, null,},
                new Object[]{
                    "ID", "Hóspede"
                }));

        hospede2L = new JLabel("Hóspede:");
        hospede2T = new JTextField(12);

        dataCHL = new JLabel("Data de Chegada:");
        dataCHT = new JTextField(7);

        dataSAL = new JLabel("Data de Saida:");
        dataSAT = new JTextField(7);

        descontoL = new JLabel("Desconto (%):");
        descontoT = new JTextField(2);

        statusL = new JLabel("Status:");
        statusT = new JTextField(6);

        tabelaQuarto = new JTable(4, 6);
        tabelaQuarto.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][]{
                    {null, null, null, null, null, null},
                    {null, null, null, null, null, null},
                    {null, null, null, null, null, null},
                    {null, null, null, null, null, null},
                    {null, null, null, null, null, null},
                    {null, null, null, null, null, null},
                    {null, null, null, null, null, null},},
                new String[]{
                    "Numero de Quarto", "Nome", "Capacidade", "Descrição", "Tipo", "Valor"
                }));



    }

    public void montarJanelaBusca() {


        this.setLayout(new GridLayout(5, 1));
        this.add(jpanelUm);
        this.add(jpanelDois);
        this.add(jpanelTres);
        this.add(jpanelQuatro);
        this.add(jpanelCinco);

        jpanelUm.setLayout(new BorderLayout(5, 5));
        jpanelUm.add(jpanelUm2, BorderLayout.NORTH);
        jpanelUm2.setLayout(new FlowLayout(FlowLayout.CENTER));
        jpanelUm2.add(tituloL);

        jpanelUm.add(jpanelUm3, BorderLayout.CENTER);
        jpanelUm3.setLayout(new BorderLayout(10, 10));
        jpanelUm3.setBorder(BorderFactory.createTitledBorder("Buscar Reservas"));
        jpanelUm3.add(jpanelUm4, BorderLayout.CENTER);
        jpanelUm4.setLayout(new FlowLayout(FlowLayout.LEFT));
        jpanelUm4.add(hospedeL);
        jpanelUm4.add(hospedeT);


        jpanelUm4.add(idReservaL);
        jpanelUm4.add(idReservaT);


        jpanelUm4.add(new JLabel("                     "));
        jpanelUm4.add(buttonBuscar);
        jpanelUm4.add(buttonListar);


        jpanelDois.setLayout(new BorderLayout(5, 5));


        jpanelDois.add(new JLabel("               "), BorderLayout.WEST);
        jpanelDois.add(jpanelDois2, BorderLayout.CENTER);
        jpanelDois2.setLayout(new BorderLayout(5, 5));
        jpanelDois2.setBorder(BorderFactory.createTitledBorder("Reservas Encontradas"));

        jpanelDois2.add(new JScrollPane(tabela));


        jpanelTres.setLayout(new BorderLayout(5, 5));
        jpanelTres.setBorder(BorderFactory.createTitledBorder("Informações Detalhadas"));

        jpanelTres.add(jpanelTres2, BorderLayout.NORTH);
        jpanelTres2.setLayout(new FlowLayout(FlowLayout.LEFT));
        jpanelTres2.add(hospede2L);
        jpanelTres2.add(hospede2T);
        jpanelTres2.add(dataCHL);
        jpanelTres2.add(dataCHT);

        jpanelTres.add(jpanelTres3, BorderLayout.CENTER);
        jpanelTres3.setLayout(new FlowLayout(FlowLayout.LEFT));
        jpanelTres3.add(dataSAL);
        jpanelTres3.add(dataSAT);
        jpanelTres3.add(descontoL);
        jpanelTres3.add(descontoT);
        jpanelTres3.add(statusL);
        jpanelTres3.add(statusT);



        jpanelQuatro.setLayout(new BorderLayout());
        jpanelQuatro.setBorder(BorderFactory.createTitledBorder("Quartos da Reserva"));
        jpanelQuatro.add(new JScrollPane(tabelaQuarto), BorderLayout.CENTER);

        jpanelCinco.setLayout(new FlowLayout(FlowLayout.CENTER));

        jpanelCinco.add(buttonAtualizar);


        jpanelCinco.add(buttonRemover);



        jpanelCinco.add(buttonFechar);









        /*this.setSize(1000, 600);

*/
        this.setVisible(true);
    }

    public JButton getButtonAtualizar() {
        return buttonAtualizar;
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == buttonFechar) {
            this.setVisible(false);
            Frame[] frame = JFrame.getFrames();
            TelaPrincipal frame1 = (TelaPrincipal) frame[0];
            frame1.add(frame1.getPanelPrincipal(), BorderLayout.CENTER);
            frame1.getPanelPrincipal().setVisible(true);

        }
        if (e.getSource() == buttonRemover) {
            JOptionPane.showMessageDialog(buttonRemover, "Reserva X do hóspede Y "
                    + "removida com sucesso", "Aviso", JOptionPane.INFORMATION_MESSAGE);


        }
        if (e.getSource() == buttonAtualizar) {
            Frame[] frame = JFrame.getFrames();
            System.out.println(frame.length);
            Frame frame1 = frame[0];
            System.out.println(frame1.getTitle());

            atualizarReservaDialog = new DialogAtualizarReserva(frame1, "Atualizar Reserva", true);
            atualizarReservaDialog.montaa();
        }

    }
}
